'use strict';

const jwt = require('jsonwebtoken');
const TOKEN_SALT = 'livelife';

// 生成jwt
function signJwt(payload) {
  return jwt.sign(payload, TOKEN_SALT, { expiresIn: 60 * 60 }); // 60* 60秒后
}

// 解密jwt
function verifyJwt(token) {
  let payload = null;
  try {
    payload = jwt.verify(token, TOKEN_SALT)
  } catch {
    return null
  }
  return payload
}

function loginResponse() {
  return {
    token: '',
    needLogin: true,
    message: '登录已过期!'
  }
}


module.exports = {
	// 公用模块用法请参考 https://uniapp.dcloud.io/uniCloud/cf-common
  signJwt,
  verifyJwt,
  loginResponse,
}
